package com.hans.scala

import scala.collection.mutable

/**
 * User: ZhangJuntao
 * Date: 2014/3/27
 * Time: 15:29
 */
object FunctionExample {
  def main(args: Array[String]) {
    def max1(x: Int, y: Int): Int = {
      if (x > y) x
      else y
    }
    val max2 = (x: Int, y: Int) => {
      if (x > y) x
      else y
    }
    println(max1(3, 2))
    println(max2(3, 2))

    val proxy = (f: (Int, Int) => Int) => f(3, 4)
    val proxy2 = (f: (Int, Int) => Int, x: Int, y: Int) => {
      println("before f")
      val t = f(x, y)
      println("after f")
      t
    }
    println(proxy((x: Int, y: Int) => {
      if (x > y) x else y
    }))
    println(proxy2((x: Int, y: Int) => {
      println("in the function")
      if (x > y) x; else y
    }, 4, 5))


    val abc = List('a', 'b', 'c')
    def iterator[U](f: List[Char] => List[U]): List[U] = {
      f(abc)
    }
    println(abc)
    iterator[Int](list => {
      for (i <- list) yield i.toInt
    }).foreach(x => print(x + " "))

  }
}


